//
//  AY_BookMyCell.m
//  AiYue
//
//  Created by boWen on 2023/10/19.
//

#import "AY_BookMyCell.h"

@interface AY_BookMyCell ()
@property (nonatomic, strong) UIView * bg_View;
@property (nonatomic, strong) UILabel * leftLabel;
@property (nonatomic, strong) UILabel * rightLabel;
@property (nonatomic, strong) UIImageView * arrowImgView;
@property (nonatomic, strong) NSArray * dataLeftAry;
@end


@implementation AY_BookMyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}

- (void)addAllSubviewsWithUI {
    if ([AYMMKV getBoolForKey:ISSHENHE defaultValue:YES]) {
        self.dataLeftAry = @[@"阅读偏好", @"在线求书", @"人工客服", @"意见反馈"];
    }else{
        self.dataLeftAry = @[@"邀请好友", @"阅读偏好", @"在线求书", @"人工客服", @"意见反馈"];
    }
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor clearColor];
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:0 andAddSubView:self.contentView];
    self.bg_View.layer.masksToBounds = NO;
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
    
    self.leftLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"邀请码" andTextColor:COLOR(@"#010101") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(14)]  andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bg_View);
        make.left.equalTo(self.bg_View).offset(YNUM(14));
        make.height.mas_equalTo(YNUM(22));
    }];
    
    self.arrowImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_my_arrowNight.png") andBg:[UIColor whiteColor] andRadius:0.0 andAddSubView:self.bg_View];
    [self.arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(YNUM(16));
        make.width.mas_equalTo(YNUM(16));
        make.right.equalTo(self.bg_View).offset(YNUM(-14));
        make.centerY.equalTo(self.bg_View);
    }];
    
    self.rightLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"限时免费领取VIP" andTextColor:COLOR(@"#BFBFBF") andBgColor:nil andFont:[UIFont systemFontOfSize:YNUM(14)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bg_View);
        make.right.equalTo(self.arrowImgView.mas_left).offset(YNUM(-4));
        make.height.mas_equalTo(YNUM(22));
    }];
    
}

- (void)setDataRightAry:(NSMutableArray *)dataRightAry {
    _dataRightAry = dataRightAry;
}

- (void)setData:(NSInteger)index andConfigModel:(ConfigModel *)model {
    self.leftLabel.text = self.dataLeftAry[index];
    if([self.leftLabel.text isEqualToString:@"在线求书"]) {
        self.rightLabel.text = model.order_quantity;
        self.rightLabel.textColor = COLOR(@"#F86923");
    } else if ([self.leftLabel.text isEqualToString:@"人工客服"]) {
        self.rightLabel.text = model.kfwork_time;
        self.rightLabel.textColor = COLOR(@"#BFBFBF");
    } else {
        self.rightLabel.text = self.dataRightAry[index];
        self.rightLabel.textColor = COLOR(@"#BFBFBF");
    }
    
    if (index == 0) {
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W - 32, YNUM(52)) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(YNUM(13), YNUM(13))];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.bg_View.bounds;
        maskLayer.path = maskPath.CGPath;
        self.bg_View.layer.mask = maskLayer;
    }else if (index == self.dataLeftAry.count - 1) {
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W - 32, YNUM(52)) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(YNUM(13), YNUM(13))];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.bg_View.bounds;
        maskLayer.path = maskPath.CGPath;
        self.bg_View.layer.mask = maskLayer;
    }else {
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W - 32, YNUM(52)) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(0, 0)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.bg_View.bounds;
        maskLayer.path = maskPath.CGPath;
        self.bg_View.layer.mask = maskLayer;
    }
}

- (void)setInfoModel:(UserInfo *)infoModel {
    _infoModel = infoModel;
    
}

- (void)setFrame:(CGRect)frame {
    frame.origin.x += 16;
    frame.size.width -= 2 * 16;
    [super setFrame:frame];
}



@end
